#include "htbl.h"


int main(int argc, char *argv[])
{
    cmemory_stack<int>     m;

    int         *ip;
    int          xx = 0,
                 test_index,
                 ff = -1;

    for( xx = 0; xx < 20; xx++ )
    {
        printf( "%ld/20\n", xx + 1 );
        srand( xx );
        int n1 = rand( ) % 100 + 1;
        int n2 = rand( ) % 100 + 1;

        if( ff < 0 )
        {
            m.create( n1, n2 );
            printf( "A" );
        }

        for( test_index = 0; test_index < rand() % 200 + 100; test_index++ )
        {
            int an = rand() % 10048 + 1,
                fn = an / 2 + rand() % 10048 / 3 + 1;
                
//            an = fn = 1;

            //printf( "Alloc [%ld]...",an );

            for( int i = 0; i < an; i++ )
            {
                ip = m.alloc_push( );
                *ip = i;
            }

            //printf( "Free [%ld]...", fn );

            for( int i = 0; i < an; i++ )
            {
                ip = m.free_pop( );
                if( ip == NULL )
                    break;
                *ip = i;
            }
        }

        //printf( "(%ld/%ld)  %ld %ld - %ld\n", xx+1, 1000, n1, n2, test_index );

        if( ff < 0 )
        {
            m.release(); 
            printf( "R" );
            m.create( n1, n2 );
            printf( "A" );
//            return 0;
        }

        if( ff >= 4 && ff < 6 )
        {
            m.release();
            printf( "R" );
            m.create( n1, n2 );
            printf( "A" );
        }

        ff = rand( ) % 10;
    }

    m.release();

    return 0;
}
